﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniCT.LinkShareWpf.Interface;
using UniCT.LinkShareWpf.Model;

namespace UniCT.LinkShareWpf.CommunicationChannel
{
    public class Client
    {
        #region Private
        IContract client;
        Channel chan;
        #endregion

        public Client(Uri target)
        {
            chan = new Channel(target);
            client = chan.Client;
        }

        public long PingRequest()
        {
            try
            {
                Console.WriteLine("Client, sto provando a pingare");
                long ticks = client.Ping(Environment.TickCount);
                long ping = Environment.TickCount - ticks;
                chan.Dispose();
                Console.WriteLine("Client,ho finito di pingare.");
                return ping;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                chan.Dispose();
                return -1;
            }
        }

        public void SingleRequest(NetFilter netFilter)
        {
            try
            {
               client.SearchRequest(netFilter);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        public void SendResourceRequest(NetResource netResource)
        {
            try
            {
                Console.WriteLine("Client, sto provando ad inviare la netResource");
                client.SendResource(netResource);
                Console.WriteLine("Client, ho inviato la netResource");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

    }
    
}
